package com.shop.controller;


import com.shop.common.result.Result;
import com.shop.common.result.util.ResultModel;
import com.shop.service.PartnerService;
import com.shop.vo.AddPartnerVo;
import com.shop.vo.SelectPartnerVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 合作商表 前端控制器
 * </p>
 *
 * @author 靳 旺
 * @since 2021-01-29
 */
@RestController
@Api(tags = "合作商前端控制器")
@RequestMapping("/partner-do")
public class PartnerController {

    @Autowired
    private PartnerService partnerService;

    @PostMapping("addPartner")
    @ApiOperation(value = "添加单条合作商",notes = "靳旺")
    public ResultModel addPartner(@RequestBody @Valid AddPartnerVo addPartnerVo, BindingResult result)throws Exception{
      if (result.hasErrors()) return Result.errorResultModel(result.getAllErrors());
      return partnerService.addPartner(addPartnerVo);
    }

    @PostMapping("addBatchPartner")
    @ApiOperation(value = "批量添加合作商",notes = "靳旺")
    public ResultModel addBatchPartner(@RequestBody @Valid List<AddPartnerVo> addPartnerVo, BindingResult result)throws Exception{
        if (result.hasErrors()) return Result.errorResultModel(result.getAllErrors());
        return partnerService.addBatchPartner(addPartnerVo);
    }

    @PostMapping("selectPartner")
    @ApiOperation(value = "查询合作商",notes = "靳旺")
    public ResultModel selectPartner(@RequestBody  SelectPartnerVo selectPartnerVo)throws Exception{
        return partnerService.selectPartner(selectPartnerVo);
    }


}
